﻿using System;
using System.Collections.Generic;
using System.Text;
using AutoMapper;
using FireBillBook.Core.Entities;
using FireBillBook.Core.Dtos;
using System.Text.Json;

namespace FireBillBook.Core.Models
{
    using Models.OriginalDatas;
    public class BillingProfile : Profile
    {
        public BillingProfile()
        {
            CreateMap<ConsumptionRecordDto, ConsumptionRecord>().ReverseMap();

            // AliPay
            CreateMap<AliPaymentOriginalData, BillingSourceData>()
                .ForMember(dest => dest.Amount, opt => opt.MapFrom(src => src.TradingAmount.Trim()))
                .ForMember(dest => dest.IncomeOrSpend, opt => opt.MapFrom(src => src.IncomeOrExpenses))
                .ForMember(dest => dest.TradingCode, opt => opt.MapFrom(src => src.TradingCode.Trim()))
                .ForMember(dest => dest.OrderCode, opt => opt.MapFrom(src => src.OrderCode.Trim()))
                .ForMember(dest => dest.TradingParty, opt => opt.MapFrom(src => src.TradingTarget.Trim()))
                .ForMember(dest => dest.ItemName, opt => opt.MapFrom(src => src.ItemName.Trim()))
                .ForMember(dest => dest.TradingStatus, opt => opt.MapFrom(src => src.TradingStatus.Trim()))
                .ForMember(dest => dest.TradingTime, opt => opt.MapFrom(src => src.TradingTime.Trim()))
                .ForMember(dest => dest.Remark, opt => opt.MapFrom(src => src.Remark.Trim()));

            // WechatPay
            CreateMap<WechatPaymentOriginalData, BillingSourceData>()
                .ForMember(dest => dest.Amount, opt => opt.MapFrom(src => src.TradingAmount.Trim()))
                .ForMember(dest => dest.IncomeOrSpend, opt => opt.MapFrom(src => src.IncomeOrExpenses))
                .ForMember(dest => dest.TradingCode, opt => opt.MapFrom(src => src.TradingCode.Trim()))
                .ForMember(dest => dest.OrderCode, opt => opt.MapFrom(src => src.OrderCode.Trim()))
                .ForMember(dest => dest.TradingParty, opt => opt.MapFrom(src => src.TradingTarget.Trim()))
                .ForMember(dest => dest.ItemName, opt => opt.MapFrom(src => src.ItemName.Trim()))
                .ForMember(dest => dest.TradingStatus, opt => opt.MapFrom(src => src.TradingStatus.Trim()))
                .ForMember(dest => dest.TradingTime, opt => opt.MapFrom(src => src.TradingTime.Trim()))
                .ForMember(dest => dest.Remark, opt => opt.MapFrom(src => src.Remark.Trim()));

        }

        static string ConvertExternalData(AliPaymentOriginalData src)
        {
            var d = new
            {
                PaymentTime = src.PaymentTime,
                LatestModifiedTime = src.LatestModifiedTime,
                TradingSource = src.TradingSource,
                TradingType = src.TradingType,
                ServicePayment = src.ServicePayment,
                SuccessRefundAmount = src.SuccessRefundAmount,
                PaymentStatus = src.PaymentStatus
            };
            return JsonSerializer.Serialize(d);
        }

        static string ConvertExternalData(WechatPaymentOriginalData src)
        {
            var d = new
            {
                TradingType = src.TradingType,
                PaymentWay = src.PaymentWay,
            };
            return JsonSerializer.Serialize(d);
        }
    }
}
